<admintpl file="header" />
</head>
<style>

</style>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="javascript:;">数据导入设置</a></li>
		</ul>
		<form action="{:U('')}" method="post" class="form-horizontal js-ajax-forms edit-form" enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th>重置日常数据</th>
							<td>
								<input type="text" id='reset_name' value='' placeholder="姓名" />
								<input type="text" id='reset_date_s' class="js-date" value="" style="width: 80px;" autocomplete="off">-
								<input type="text" id='reset_date_e' class="js-date" value="" style="width: 80px;" autocomplete="off">
								<a href='javascript:;' class="btn btn-primary btn-small" id='reset' >重置</a>
							</td>
						</tr>
					</table>
				</div>
				<div class="span1"><textarea name="" id="rundetial" style="display:block;" cols="30" rows="10"></textarea></div>
			</div>
		</form>
	</div>

	<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
	var days = '';
	var _date_s = '';
	var _rundetial = $('#rundetial');
	var _this=$('#reset_apply');
	
	$('#reset_apply').click(function(){
		var _name = $('#reset_name').val();
		var _date_s = $("#reset_date_s").val();
		var _date_e = $("#reset_date_e").val();
		count_days();
		reset_apply(_name,_date_s,0);
	})
	
	function count_days(){
		
		_date_s = $("#reset_date_s").val();
		var _date_e = $("#reset_date_e").val();
		if (!_date_e) {
			alert('请设置起止时间！！');
			return false;
		}
		_rundetial.css('display','block');
		_rundetial.empty();
		
		//计算日期天数
		var _date_s_stamp = Date.parse(new Date(_date_s))/1000;
		var _date_e_stamp = Date.parse(new Date(_date_e))/1000;
		days = parseInt((_date_e_stamp-_date_s_stamp)/86400)+1;
		var loadimg = '<span id="loadimg"><img src="__PUBLIC__/simpleboot/loading.gif"  width="65" alt="" /><span>正在执行中.......</span></span>';
		
		_this.after(loadimg);
		_this.hide();
	}
	
	//对比日期
	function CompareDate(d1,d2){
	  return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
	}
	
	
	$('#reset').click(function(){
		var _name = $('#reset_name').val();
		var _date_s = $("#reset_date_s").val();
		var _date_e = $("#reset_date_e").val();
		var timeflag = CompareDate(_date_s,_date_e);
		
		if (timeflag && (_date_s !== _date_e)) {
			alert('时间前后有问题,请检查！');
			return ;
		}
		if (_name == '') {
			alert('请输入姓名！！');
			return ;
		}
		
		if (_date_s == '' || _date_e == ''){
			alert('请设置起止时间');
			return ;			
		}
		
		
		count_days();
		getAjax(0);
		function getAjax(i){
 			$.ajax({
				url:"{:U('flash_user')}",
				data:{'name':_name,'date_s':_date_s,'days':i},
				type:'post',
				success:function(ret){
					if (ret){
						_rundetial.prepend(ret.msg+"\n");
						
						if (days == i+1) {
							//$('#loadimg').hide();
							//_this.show();
							
							//alert('操作完成！');
							reset_apply(_name,_date_s,0);
							return false;
						}
						i++;
						getAjax(i);
					}
				}
			}) 
		}
		
		
		
		
	})
		var _dealid = '';
		function reset_apply(_name,_date_s,i){
 			$.ajax({
				url:"{:U('flash_user_apply')}",
				data:{'name':_name,'date_s':_date_s,'days':i,'deal_id':_dealid},
				type:'post',
				success:function(ret){
					if (ret){
						_dealid = ret.deal_id;
						if (ret.msg){
							_rundetial.prepend(ret.msg+"\n");
						}
						
						if (days == i+1) {
							$('#loadimg').hide();
							_this.show();
							_dealid = '';
							alert('操作完成！');
							return false;
						}
						i++;
						reset_apply(_name,_date_s,i);
					}
				}
			}) 
		}
		

	 
	    
	 </script>
</body>
</html>